﻿/***************************************************************
 * 开发人员：网魂小兵@http://www.mozlite.com
 * 
 * 目标标本：4.0.30319.239
 * 
 * 最后修改：2011/12/19 18:37:54
 * ************************************************************/
namespace Mozlite.Web.Controls
{
    using System;
    using System.Linq;
    using System.Text;
    using System.Collections.Generic;
    using System.Web.Mvc;
    using System.Web.Mvc.Html;
    using System.Linq.Expressions;
    using Mozlite.Common;

    /// <summary>
    /// 多选项列表框。
    /// </summary>
    public static class CheckBoxListControl
    {
        /// <summary>
        /// 分类多选列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">Lumbda表达式。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString MediaCategoryCheckBoxListFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, string>> expression, ButtonFormatter formatter = ButtonFormatter.Horizontal, Dictionary<string, string> attributes = null)
        {
            List<SelectListItem> items = new List<SelectListItem>();
            foreach (var category in MediaManager.LoadCategories().Values)
            {
                items.Add(new SelectListItem { Text = category.CategoryName, Value = category.CategoryID.ToString() });
            }
            return helper.CheckBoxListFor(expression, items, formatter, attributes);
        }
    }
}